package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmMaterialDto;
import com.heima.model.wemedia.pojos.WmMaterial;
import com.heima.wemedia.service.WmMaterialService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


@RestController
@RequestMapping("/api/v1/material")
public class WmMaterialController {

    @Autowired
    private WmMaterialService wmMaterialService;


    @PostMapping("/upload_picture")
    public ResponseResult uploadPicture(MultipartFile multipartFile) {

        return wmMaterialService.uploadPicture(multipartFile);
    }

    @PostMapping("list")
    public ResponseResult list(@RequestBody WmMaterialDto wmMaterialDto) {
        return wmMaterialService.getList(wmMaterialDto);
    }

    @GetMapping("collect/{id}")
    public ResponseResult updateStatus(WmMaterial v) {
        v.setIsCollection((short) 1);
        wmMaterialService.updateById(v);
        return ResponseResult.okResult("success");
    }

    @GetMapping("del_picture/{id}")
    public ResponseResult del(@PathVariable Integer id) {
       return wmMaterialService.del(id);
    }
}